<?php
 namespace Admin\Controller;
 use Think\Controller;

 class ConfigController extends Controller

 {
   
   public function index()

   {
      // 实例化model
      $model = M('config');
      // 查询数据
      $data = $model->select();
      // dump($data);

      $this->assign('data',$data);
      $this->display();
       
   }

    public function insert()

   {
        $data =I('post.');
         // dump($data);
        $model = M('config');

      $config = array(

        'rootPath' => 'Public/',        
        'maxSize'    =>    3145728,  
        'savePath'   =>    './Public/Uploads/', 
        'saveName'   =>    array('uniqid',''),   
        'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'), 
       'autoSub'    =>    true,   
       'subName'    =>    array('date','Ymd'),

      );

    $upload = new \Think\Upload($config);

    // 2.执行文件上传操作(单文件上传)
    $info = $upload->uploadOne($_FILES['logo']);

    // dump($info);
   
    // 判断文件上传是否成功
    if($info){
         
         $data['logo'] = $info['savepath'].$info['savename'];

    }else{

         echo $upload->getError();
    }

       // dump($data);

    $result = $model->add($data);
    // dump($result);

    if($result){

            $this->success('添加成功',U('Config/index'),3);
    }else{
           
           // echo $this->error('添加失败');
    }

  }


   public function find()

   {
     
      // 实例化
     $model =M('config');
     $data = $model->find(I('get.id'));

     $this->assign('data',$data);
     $this->display('Config/update');

   }

   public function update()

   {
        $data =I('post.');
        // dump($data);
        $model=M('config');

      $config = array(

        'rootPath' => 'Public/',        
        'maxSize'    =>    3145728,  
        'savePath'   =>    './Public/Uploads/', 
        'saveName'   =>    array('uniqid',''),   
        'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'), 
       'autoSub'    =>    true,   
       'subName'    =>    array('date','Ymd'),

      );

    $upload = new \Think\Upload($config);

    // 2.执行文件上传操作(单文件上传)
    $info = $upload->uploadOne($_FILES['logo']);

    // dump($info);
   
    // 判断文件上传是否成功
    if($info){
         
         $data['logo'] = $info['savepath'].$info['savename'];

    }else{

         echo $upload->getError();
    }

     // dump($data);

    $result = $model->save($data);

    if($result){

            $this->success('修改成功',U('Config/index'),3);
    }else{
           
           echo $this->error('修改失败');
    }




   }

   public function destroy()

   {
     
      $model = M('config');
      $data['id'] =I('get.id');
      $data['status'] = 0;

       // dump($data);
      $result = $model->save($data);

      if($result){
          
              $this->success('禁止成功',U('Config/index'),3);

      }else{

             echo $this->error('禁止失败');
      }

    }

   public function qi()

   {
     
      $model = M('config');
      $data['id'] =I('get.id');
      $data['status'] = 1;

        // dump($data);
      $result = $model->save($data);

      if($result){
          
              $this->success('启用成功',U('Config/index'),3);

      }else{

             echo $this->error('启用失败');
      }



   }

   



 }